package com.jic.veteran.service.impl;

import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.jic.veteran.common.exception.Asserts;
import com.jic.veteran.mapper.PayInfoMapper;
import com.jic.veteran.mapper.ReconResultMapper;
import com.jic.veteran.model.PayInfo;
import com.jic.veteran.model.ReconResult;
import com.jic.veteran.service.ReconResultService;
import com.jic.veteran.service.UmsAdminCacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReconResultServiceImpl implements ReconResultService {

    @Autowired
    ReconResultMapper reconResultMapper;

    @Autowired
    PayInfoMapper payInfoMapper;

    @Autowired
    UmsAdminCacheService umsAdminCacheService;

    @Override
    public List<ReconResult> getReconResults(String reconDate, Integer pageSize, Integer pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        return reconResultMapper.getReconResults(reconDate);
    }

    @Override
    public List<PayInfo> getPayInfoList(Integer pageSize, Integer pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        return payInfoMapper.getPayInfoList();
    }
    @Override
    public int updatePayInfo(Long id,String status) {
        PayInfo payInfo = payInfoMapper.getPayInfoStatus();
        PayInfo payInfoCurrent = payInfoMapper.getPayInfoById(id);
        if(payInfoCurrent != null && payInfo != null) {
            if(payInfo.getId()!=payInfoCurrent.getId()) {
                return -1;
            }
        }
        int result = payInfoMapper.updatePayInfo(id,status);
        if (result > 0) {
            payInfo = payInfoMapper.getPayInfoStatus();
            if (payInfo != null) {
                umsAdminCacheService.setPayInfo(payInfo);
            } else {
                umsAdminCacheService.setPayInfo(null);
            }
        }
        return result;
    }
}
